<template>
  <DaprPlusTable
    :table-title="$t('fsb.games.gameRole.list')"
    :entity="entity"
    :grid-options="gridOptions"
    :query-api="crudApi.getPage"
    :delete-api="crudApi.delete"
    :show-create="false"
    :show-edit="false"
    @update:grid-api="onGridApiUpdate"
  />
</template>

<script setup lang="ts">
import type { ExtendedVxeGridApi, VxeGridProps } from '#/adapter/vxe-table';
import { DaprPlusTable } from '#/components/daprplus';
import { createCrudApi } from '#/api/daprplus';
import type { IOutDto, EntityInfo } from '#/utils/daprplus';
import { createBooleanColumn } from '#/utils/daprplus';
import { $t } from '#/locales';

const baseUrl = '/games/api/gamerole';
const crudApi = createCrudApi<GameRoleOutDto, GameRoleOutDto>(baseUrl);

const entity: EntityInfo = {
  code: 'GameRole',
  display: $t('fsb.games.gameRole.title'),
};

// 扩展配置
const gridOptions: VxeGridProps<GameRoleOutDto> = {
  columns: [
    { type: 'checkbox', width: 40 },
    {
      field: 'id',
      title: '编号',
      sortable: true,
      width: 100,
    },
    {
      field: 'name',
      title: '角色名',
      sortable: true,
      align: 'left',
      minWidth: 120,
    },
    {
      field: 'vocation',
      title: '职业',
      sortable: true,
      width: 100,
    },
    {
      field: 'level',
      title: '等级',
      sortable: true,
      width: 80,
    },
    {
      field: 'levelSky',
      title: '天等级',
      sortable: true,
      width: 100,
    },
    {
      field: 'society',
      title: '公会',
      align: 'left',
      minWidth: 120,
    },
    {
      field: 'moneyInBag',
      title: '背包金钱',
      sortable: true,
      width: 120,
    },
    {
      field: 'moneyInRepertory',
      title: '仓库金钱',
      sortable: true,
      width: 120,
    },
    {
      field: 'account',
      title: '账号',
      align: 'left',
      minWidth: 120,
    },
    createBooleanColumn('isLocked', '锁定', {
      sortable: true,
      width: 100,
    }),
    {
      field: 'lastDate',
      title: '最后登录',
      formatter: 'formatDateTime',
      width: 130,
    },
    {
      field: 'createdTime',
      title: '创建时间',
      formatter: 'formatDateTime',
      width: 130,
    },
  ],
};

let gridApi: ExtendedVxeGridApi;

function onGridApiUpdate(api: ExtendedVxeGridApi) {
  gridApi = api;
}

export interface GameRoleOutDto extends IOutDto {
  name?: string;
  vocation?: string;
  level?: number;
  levelSky?: number;
  society?: string;
  moneyInBag?: number;
  moneyInRepertory?: number;
  account?: string;
  isLocked?: boolean;
  lastDate?: Date;
  createdTime?: Date;
}
</script>

<style scoped></style>
